home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
14642
/
14642.xpi
/
chrome
/
modules
/
trackers
/
search.js
< prev
next >
Wrap
Text File
|
2009-10-19
|
4KB
|
103 lines
/* Copyright 2009, Boomtango.com. All Rights Reserved. */
/* search.js
* Responsible for tracking search results
*/
var EXPORTED_SYMBOLS = ["search"];
var search = {
name: "Search",
name_plural: "Searches",
color: "#9F3628",
isInternal: true,
preview: function(doc, node, data){
if(data.preview){
var result = this.json.decode(data.preview);
var len = result.results.length;
if(len){
var searchTitle = doc.createElement("label");
searchTitle.className = "searchPreviewTitle";
searchTitle.setAttribute("flex", "1");
searchTitle.setAttribute("crop", "end");
searchTitle.setAttribute("value",
this.app.getString("type.search.title")
);
node.appendChild(searchTitle);
for(var x = 0; x < len; x++){
var item = result.results[x];
var hbox = doc.createElement("hbox");
node.appendChild(hbox);
var imgBox = doc.createElement("box");
imgBox.setAttribute("align", "center");
imgBox.setAttribute("pack", "center");
imgBox.className = "searchPreviewBulletBox";
hbox.appendChild(imgBox);
var img = doc.createElement("image");
img.setAttribute("src", "chrome://boomtango/skin/bullet_circle.png");
imgBox.appendChild(img);
var label = doc.createElement("label");
label.className = "text-link searchPreviewResult";
label.setAttribute("value", item.title);
label.setAttribute("flex", "1");
label.setAttribute("href", item.url);
label.setAttribute("crop", "end");
hbox.appendChild(label);
}
}
}
},
onLoadTracks: function(url, doc){
var result = [];
if(this.pattern.exec(url)){
var qr = url.match(/q=([^&]+)(&|$)/);
var query = "";
if(qr.length >= 2){
query = qr[1];
}
result.push(
{
type: "search",
preview: this._buildSnippet(doc, query),
content: query
}
);
}
return result;
},
_buildSnippet: function(doc, query){
var result = { query: query, results: []};
if(doc){
var a = doc.getElementsByTagName("a");
var len = a.length;
var maxfound = 10;
for(var i =0; i < len; i++){
var item = a[i];
if(item.className == "l" &&
item.parentNode && item.parentNode.className == "r" &&
item.parentNode.nextSibling &&
(item.parentNode.nextSibling.className== "s" ||
item.parentNode.nextSibling.tagName == 'SPAN')){
var entry = { title: item.textContent, url: item.href };
if(!maxfound){
break;
} else {
result.results.push(entry);
maxfound--;
}
}
}
}
return this.json.encode(result);
},
json: Components.classes["@mozilla.org/dom/json;1"].createInstance(Components.interfaces.nsIJSON),
pattern: /(http:\/\/www\.google\..+\/.*[?&]q=([^&]+))|(http:\/\/[-a-zA-Z]+\.start3\.mozilla\.com\/search\?.*[?&]q=([^&]+))/
};